<template>
  <div class="tabber">
    <ul>
        <li v-for="(item, index) in routerList" :key="index"
        @click="switchRouter(item.path)">
            <van-icon :name="$route.path === item.path? item.selected : item.name" size="31px"/>
            <span>{{ item.title }}</span>
        </li>
    </ul>
  </div>
</template>

<script>
export default {
    data(){
        return{
            routerList:[
                {
                    title:'首页',
                    name:'wap-home-o',
                    path:'/home',
                    selected:'wap-home'      
                },
                {
                    title:'分类',
                    name:'cluster-o',
                    path:'/list',
                    selected:'cluster'   
                },
                {
                    title:'购物车',
                    name:'cart-o',
                    path:'/cart',
                    selected:'cart'         
                },
                {
                    title:'我的',
                    name:'contact-o',
                    path:'/my',   
                    selected:'contact'      
                }
            ]
        }
    },
    methods:{
        switchRouter(path){
            if(this.$route.path == path) return

            this.$router.replace(path)
        }
    }
}
</script>

<style scoped>
.tabber {
    position: fixed;
    left: 0;
    bottom: 0;
    /* 覆盖值较小的数据 */
    z-index: 999;
    width: 100%;
    height: 56px;
    background-color: white;
}
.tabber ul {
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
    height: 100%;
}
.tabber ul li {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.tabber ul li span{
    font-size: 15px;
}
</style>